﻿using Estsh.Core.Model.EnumUtil;
using Estsh.Core.Models;
using Estsh.Core.Quartz.BaseService;
using Estsh.Core.Util;
using Estsh.Core.Wms.IRepositories;

namespace Estsh.Core.Wms.Jobs
{
    /// <summary>
    /// 库存零件原材料 扣减
    /// </summary>
    public class ProductDeductJob : IJobService
    {
        private readonly IProductDeductRepository productDeduct;

        public ProductDeductJob(IProductDeductRepository _productDeduct)
        {
            this.productDeduct = _productDeduct;
        }

        public string ExecuteService(string parameter)
        {
            try
            {
                List<SysStock> wmsProducts = productDeduct.GetProductDeductInfo();
                if (wmsProducts.Count <= 0)
                {
                    return "没有待扣减的数据！";
                }

                bool bl = productDeduct.InsertProductDeductInfo();
                if (bl == true)
                {
                    return "待扣减原材料数据同步成功！";
                }
                else
                {
                    return "待扣减原材料数据同步失败！";
                }

            }
            catch (Exception ex) 
            {
                LogHelper.Error("生成库存零件扣减错误！" + ex);
                return "生成库存零件扣减错误！" + ex.Message;
            }
        }
    }
}
